#author 	lemon
#date   	2010.10.31
#purpose	download all pic and links pics from one brower

use LWP::Simple;

$url       = 'http://www.1chu.com/';
$save_main_dir = "d:\\pic";
$save_dir =  "d:\\pic\\zhaojiling";
$save_dir_sub = "d:\\pic\\zhaojiling\\jpg";
$save_path = "d:\\pic\\zhaojiling\\jpg\\";

mkdir $save_main_dir or warn "can not create dir $save_main_dir: $!\n";
mkdir $save_dir or warn "can not create dir $save_dir: $!\n";
mkdir $save_dir_sub or warn "can not create dir $save_dir_sub: $!\n";
$pic_suffix  = ".jpg";
$html_suffix = ".html";
$filename    = 1;
$content     = get $url;


get_pic( $pic_suffix, $content );
print " there is all your want !";

sub get_html {
	my $suffix  = $_[0];
	my $content = $_[1];
	while ( $content =~ m/("|')http:\/\/(\S+)$suffix('|")/g ) {
		print "http://$2$suffix\n";
		my $html_url     = "http://$2$suffix";
		if($html_url eq ""){
			return;
		}
		my $content_next = get $html_url;
		get_pic( $pic_suffix, $content_next );
	}
}

sub get_pic {
	my $pic_suffix  = $_[0];
	my $pic_content = $_[1];
	if($pic_content eq ""){
		return;
	}
	my $path_deep   = 1;
	while ( $pic_content =~ m/('|")http:\/\/(\S+)$pic_suffix('|")( +|\S+)/g ) {
		print "http://$2$pic_suffix\n";
		my $pic_url     = "http://$2$pic_suffix\n";
		my $pic_content = get $pic_url;
		my $pic_path    = "$save_path$filename$pic_suffix";
		$filename++;
		getstore( $pic_url, $pic_path ) or die "get picture failed!";
	}
	$path_deep++;
	if ( $path_deep < 3 ) {
		get_html( $html_suffix, $pic_content );
	}

}









